package com.example.main.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;
import com.example.main.dao.HistoryMapper;
import com.example.main.dao.ServicesMapper;
import com.example.main.entity.HistoryEntity;
import com.example.main.entity.ServicesEntity;
import com.example.main.service.HistoryService;
import com.example.main.service.ServicesService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, HistoryEntity> implements HistoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String sort = params.getOrDefault("sort", "descending") + "";

        QueryWrapper<HistoryEntity> wrapper = new QueryWrapper<>();
        if("descending".equals(sort)) {
            wrapper.orderByDesc("occurence_time");
        }else {
            wrapper.orderByAsc("occurence_time");
        }

        IPage<HistoryEntity> page = this.page(
                new Query<HistoryEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }
}
